from django.db import models
from userapp.models import BaseModel

# Create your models here.
# 设计 广告分类表
class AdvCategory(BaseModel):
    name = models.CharField('广告分类名', max_length=20)
    key = models.SmallIntegerField('广告分类关键字')

    class Meta:
        verbose_name = "广告分类"
        verbose_name_plural = verbose_name


# 设计 广告内容表
class AdvContent(models.Model):
    title = models.CharField("广告标题", max_length=20)
    pic = models.ImageField(upload_to='adv', verbose_name="广告图片", null=True, blank=True)
    url = models.CharField('超链接', max_length=120)
    category = models.ForeignKey(AdvCategory, on_delete=models.CASCADE, verbose_name="所属分类")
    sort = models.SmallIntegerField('排序')  # 顺序

    class Meta:
        verbose_name = "广告内容"
        verbose_name_plural = verbose_name


# 设计 分类频道/组
class Channel(models.Model):
    name = models.CharField(max_length=20)
    sorted = models.SmallIntegerField('排序')

    class Meta:
        db_table = "channels"
        verbose_name = "频道"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


# 分类model
class Category(models.Model):
    name = models.CharField(max_length=20)
    channel = models.ForeignKey(Channel, on_delete=models.CASCADE)
    parent = models.ForeignKey("self", on_delete=models.SET_NULL, null=True, blank=True)
    level = models.SmallIntegerField('分类层级', default=1)
    pic = models.ImageField(upload_to="category", null=True)

    class Meta:
        db_table = "category"
        verbose_name = "类目"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name + str(self.level)


#  设计出 商品model

class Goods(models.Model):
    name = models.CharField(max_length=120)
    name1 = models.CharField(max_length=120)
    price = models.DecimalField(max_digits=8, decimal_places=2)
    comments = models.IntegerField('评论次数', default=0)
    content = models.TextField('详情')
    pic = models.ImageField(upload_to="goods")
    stock = models.IntegerField('库存')
    sale = models.IntegerField('销量', default=0)
    category1 = models.IntegerField()
    category2 = models.IntegerField()
    category3 = models.IntegerField()


# 定义一个规格值model
class Specify(models.Model):
    name = models.CharField(max_length=20)
    value = models.CharField(max_length=20)
    goods = models.ForeignKey(Goods, on_delete=models.SET_NULL, null=True)
